package com.exam.api.common.exception;


import cn.hutool.core.util.StrUtil;
import com.exam.api.common.web.ResultCode;
import lombok.Getter;
import lombok.Setter;


/**
 * @Author Bcheng
 * @Create 2021/4/16 上午 10:45
 * @Description 全局异常
 */
@Setter
public class GlobalException extends RuntimeException {
    /**
     * 消息状态码
     */
    @Getter
    private Integer code = ResultCode.FAILURE.getCode();
    /**
     * 消息
     */
    private String message = ResultCode.FAILURE.getMessage();


    public GlobalException() {
        super();
    }

    public GlobalException(String message) {
        super(message);
        this.setMessage(message);
    }

    public GlobalException(String message, Object... params) {
        super(StrUtil.format(message, params));
        this.setMessage(StrUtil.format(message, params));
    }

    public GlobalException(ResultCode status, Object... params) {
        super(StrUtil.format(status.getMessage(), params));
        this.setCode(status.getCode());
        this.setMessage(StrUtil.format(status.getMessage(), params));
    }

    public GlobalException(Throwable cause) {
        super(cause);
    }

    @Override
    public String getMessage() {
        return message;
    }
}
